function show_order_list() {
    $.ajax({
        url: "get_meal_list",
        type: "GET",
        dataType: "json",
        success: function (data) {
            var nameAndForm = new NameAndForm(data[1],data[0]);
            var orderFormController = new OrderFormController(nameAndForm.get_ordered_name(),nameAndForm.get_not_ordered_name(),data[0]);
            orderFormController.show_ordered_name_count();
            orderFormController.show_ordered_list();
            orderFormController.show_not_ordered_name_and_count();
            orderFormController.show_total();
        }
    })
}

function OrderFormController(orderedName,notOrderedName,orderForm){
    this.orderedName = orderedName;
    this.notOrderedName = notOrderedName;
    this.orderForm = orderForm;
}

OrderFormController.prototype.show_ordered_name_count = function(){
    var orderedName = this.orderedName;
    var show_name_ordered = "<div class='order_meal_count'>" + orderedName.length + "人已定" + "</div>";
    $("body").append(show_name_ordered);
};

OrderFormController.prototype.show_ordered_list = function(){
    var orderForm = this.orderForm;
    orderForm.forEach(function (list) {
        if(list.MealPrice === null){
        }else {
            var color = (list.MealPrice.substring(1, list.MealPrice.length) > 12) ? 'red' : 'black';
            var show_meal_msg = "<div><ul><li class='order_meal_list'><p class='name'>" + list.Name + "</p><p class='set_meal'>"
                + list.RestaurantMeal + " " + list.RestaurantName + "</p><span class='price_show' style='color: " + color + "'>" + list.MealPrice + "</span>" + "</li></ul></div>";
            $("body").append(show_meal_msg);
        }
    });
};

OrderFormController.prototype.show_not_ordered_name_and_count = function(){
    var notOrderedName = this.notOrderedName;
    var show_name_not_ordered = "<div class='no_order_meal_count'>" + notOrderedName.length + "人未订" + "</div>";
    $("body").append(show_name_not_ordered);
    notOrderedName.forEach(function (name) {
        var show_name_not_ordered = "<div><ul><li class='no_order_name'>" + name + "</li></ul></div>";
        $("body").append(show_name_not_ordered);
    })
};

OrderFormController.prototype.show_total = function(){
    var sum = 0;
    var notOrderedName = this.notOrderedName;
    var orderForm = this.orderForm;
    orderForm.forEach(function (meal) {
        var price = JSON.parse(meal.MealPrice.substring(1, meal.MealPrice.length));
        sum += price;
    });
    var get_total_list = "<div><p class='all_subtotal'>" + orderForm.length + "人已订," + notOrderedName.length + "人未定,总计" + sum.toFixed(2) + "元" + "</p></div>";
    $("body").append(get_total_list);
};